<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>ADO.NET - The .NET Core ORM Cookbook</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" href="css/theme.css" type="text/css" />
    <link rel="stylesheet" href="css/theme_colors.css" type="text/css" />
    <link rel="stylesheet" href="css/styles/vs.css">
    <link rel="stylesheet" href="css/font-awesome.4.5.0.min.css">
</head>
<body role="document">
    <div class="grid-for-nav">
        <nav data-toggle="nav-shift" class="nav-side stickynav">
            <div class="side-nav-search">
                <a href="index.htm"><i class="fa fa-home"></i> The .NET Core ORM Cookbook</a>
                <div role="search">
                    <form id="search-form" class="form" action="Docnet_search.htm" method="get">
                        <input type="text" name="q" placeholder="Search docs" />
                    </form>
                </div>
            </div>
            <div class="menu menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="tocentry"><a href="index.htm">Home</a>
</li>

<li class="tocentry">
<ul>
<li><span class="navigationgroup"><i class="fa fa-caret-down"></i> <a href="ORMs.htm">ORMs</a></span></li>
<li class="tocentry current"><a class="current" href="ADO.htm">ADO.NET</a>
<ul class="currentrelative">
<li class="tocentry"><a href="#supported-databases">Supported Databases</a></li>

<li class="tocentry"><a href="#libraries">Libraries</a></li>

<li class="tocentry"><a href="#setup">Setup</a></li>

<li class="tocentry"><a href="#documentation-and-tutorials">Documentation and Tutorials</a></li>

<li class="tocentry"><a href="#bug-reporting">Bug Reporting</a></li>

<li class="tocentry"><a href="#licensing">Licensing</a></li>



</ul>
<li class="tocentry"><a href="Chain.htm">Chain</a>
</li>
<li class="tocentry"><a href="Dapper.htm">Dapper</a>
</li>
<li class="tocentry"><a href="DbConnector.htm">DbConnector</a>
</li>
<li class="tocentry"><a href="EF6.htm">Entity Framework 6</a>
</li>
<li class="tocentry"><a href="EFCore.htm">Entity Framework Core</a>
</li>
<li class="tocentry"><a href="LinqToDB.htm">LINQ to DB</a>
</li>
<li class="tocentry"><a href="LLBLGenPro.htm">LLBLGen Pro</a>
</li>
<li class="tocentry"><a href="NHibernate.htm">NHibernate</a>
</li>
<li class="tocentry"><a href="RepoDb.htm">RepoDb</a>
</li>
<li class="tocentry"><a href="ServiceStack.htm">ServiceStack</a>
</li>

</ul>
</li>
<li class="tocentry"><a href="FAQ.htm">FAQ</a>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="StandardCRUDscenarios.htm">Standard CRUD scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Fetchingdatascenarios.htm">Fetching data scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Advancedscenarios.htm">Advanced scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Sortingscenarios.htm">Sorting scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Storedprocedurescenarios.htm">Stored procedure scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Auditingandhistoryscenarios.htm">Auditing and history scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Multi-Tenancyscenarios.htm">Multi-Tenancy scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="UnknownDatabasescenarios.htm">Unknown Database scenarios</a></span>
</li>
</ul>
				<div class="toc-footer">
					<span class="text-small">
						<hr/>
						<a href="https://github.com/FransBouma/DocNet" target="_blank">Made with <i class="fa fa-github"></i> DocNet</a>
					</span>
				</div>	
			</div>
            &nbsp;
        </nav>
        <section data-toggle="nav-shift" class="nav-content-wrap">
            <nav class="nav-top" role="navigation" aria-label="top navigation">
                <i data-toggle="nav-top" class="fa fa-bars"></i>
                <a href="index.htm">The .NET Core ORM Cookbook</a>
            </nav>
            <div class="nav-content">
                <div role="navigation" aria-label="breadcrumbs navigation">
                    <div class="breadcrumbs">
<ul><li><a href="index.htm">Home</a></li> / <li><a href="ORMs.htm">ORMs</a></li> / <li><a href="ADO.htm">ADO.NET</a></li></ul>
					
                    </div>
                    <hr />
                </div>
                <div role="main">
                    <div class="section">
<h1 id="ado.net">ADO.NET<a class="headerlink" href="#ado.net" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h1>
<p>ADO.NET, also known as <code>System.Data</code>, is the foundational library for database access in .NET. This is done via a set of interfaces and abstract classes, allowing for a consistent experience.</p>
<p>Of these, the most important are <a href="https://docs.microsoft.com/en-us/dotnet/api/system.data.idbconnection" target="_blank"><code>IDbConnection</code></a>, <a href="https://docs.microsoft.com/en-us/dotnet/api/system.data.idbcommand" target="_blank"><code>IDbCommand</code></a>, and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.data.idatareader" target="_blank"><code>IDataReader</code></a>.</p>
<h2 id="supported-databases">Supported Databases<a class="headerlink" href="#supported-databases" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>All databases that offer OleDB or ODBC connectivity are automatically supported. </p>
<p>Most databases also implement their own ADO.NET provider.  that implements the ADO.NET interfaces and abstract classes. This allows greater access to the specific database's capabilities than using the generic OleDB or ODBC drivers.</p>
<p>ADO.NET requires the writing of SQL, which is often database specific.</p>
<div class="alert alert-warning"><span class="alert-title"><i class="fa fa-warning"></i> Warning!</span><p>Unless otherwise indicated, all examples of SQL are for SQL Server.</p>
</div><h2 id="libraries">Libraries<a class="headerlink" href="#libraries" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>ADO.NET is incorporated into .NET Framework. This includes the SQL Server, OleDB, and ODBC libraries.</p>
<p>For .NET Core, you'll need the <a href="https://www.nuget.org/packages/System.Data.Common" target="_blank">System.Data.Common</a> package.</p>
<ul>
<li>Db2 <a href="https://www.nuget.org/packages/IBM.Data.DB2.Core" target="_blank">IBM.Data.DB2.Core</a></li>
<li>Firebird: <a href="https://www.nuget.org/packages/FirebirdSql.Data.FirebirdClient" target="_blank">FirebirdSql.Data.FirebirdClient</a></li>
<li>MySQL: <a href="https://www.nuget.org/packages/MySqlConnector" target="_blank">MySqlConnector</a></li>
<li>Oracle DB: <a href="https://www.nuget.org/packages/Devart.Data.Oracle" target="_blank">Devart.Data.Oracle</a></li>
<li>PostgreSQL: <a href="https://www.nuget.org/packages/Npgsql" target="_blank">Npgsql</a></li>
<li>Progress OpenEdge <a href="https://www.nuget.org/packages/" target="_blank"></a></li>
<li>SQL Server: <a href="https://www.nuget.org/packages/Microsoft.Data.SqlClient" target="_blank">Microsoft.Data.SqlClient</a> or <a href="https://www.nuget.org/packages/System.Data.SqlClient" target="_blank">System.Data.SqlClient</a></li>
<li>SQLite: <a href="https://www.nuget.org/packages/System.Data.SQLite.Core" target="_blank">System.Data.SQLite.Core</a></li>
</ul>
<h2 id="setup">Setup<a class="headerlink" href="#setup" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>No special setup is needed for ADO.NET beyond just a connection string. </p>
<pre><code class="cs">/// &lt;summary&gt;
/// Opens a database connection.
/// &lt;/summary&gt;
/// &lt;remarks&gt;Caller must dispose the connection.&lt;/remarks&gt;
protected SqlConnection OpenConnection()
{
    var con = new SqlConnection(m_ConnectionString);
    con.Open();
    return con;
}
</code></pre>

<p>The exact class names vary by database.</p>
<pre><code class="cs">/// &lt;summary&gt;
/// Opens a database connection.
/// &lt;/summary&gt;
/// &lt;remarks&gt;Caller must dispose the connection.&lt;/remarks&gt;
protected NpgsqlConnection OpenConnection()
{
    var con = new NpgsqlConnection(m_ConnectionString);
    con.Open();
    return con;
}
</code></pre>

<p>For information on creating connection strings, try <a href="https://www.connectionstrings.com/" target="_blank">The Connection Strings Reference</a>.</p>
<h2 id="documentation-and-tutorials">Documentation and Tutorials<a class="headerlink" href="#documentation-and-tutorials" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<ul>
<li><a href="https://docs.microsoft.com/en-us/dotnet/api/system.data" target="_blank">Primary Documentation</a></li>
</ul>
<p>Individual ADO.NET providers may have their own documentation as well. </p>
<h2 id="bug-reporting">Bug Reporting<a class="headerlink" href="#bug-reporting" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>Most ADO.NET bugs should be reported to their respective provider maintainers. </p>
<p>For ADO.NET itself, issues should be logged in the <a href="https://github.com/dotnet/runtime/labels/area-System.Data" target="_blank">dotnet/runtime repository</a>.</p>
<h2 id="licensing">Licensing<a class="headerlink" href="#licensing" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>ADO.NET itself is offered under the <a href="https://github.com/dotnet/runtime/blob/master/LICENSE.TXT" target="_blank">The MIT License</a>.</p>
<p>Individual ADO.NET providers may be licensed differently.</p>

                    </div>
                </div>
                <footer>
                    <hr />
                    <div role="contentinfo">
The ORM Cookbook. <a href='https://github.com/Grauenwolf/DotNet-ORM-Cookbook' target='_blank'>Visit us at GitHub</a>.
                    </div>
                </footer>
            </div>
        </section>
    </div>
    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/modernizr-2.8.3.min.js"></script>
    <script src="js/highlight.pack.js"></script>
    <script src="js/theme.js"></script>

</body>
</html>
